package config

import "sync"

/**
 * description：
 * <p>
 * </p>
 * change history:
 * date                      defect#    person       comments
 * -------------------------------------------------------------<p>
 * 2023/10/10 17:05          ********    kong.ruo    create file.
 *
 * @author kong.ruo
 * @date 2023/10/10 17:05
 *
 * @since go 1.20
 */

var updateChainInstance *UpdateChain
var updateChain sync.Once

type UpdateChain struct {
	filterColumns []string
}

func GetUpdateChain() *UpdateChain {
	updateChain.Do(func() {
		updateChainInstance = &UpdateChain{filterColumns: make([]string, 0)}
	})
	return updateChainInstance
}

func (uc *UpdateChain) HandleChain(in *FilterChainIn) bool {
	mark := in.Mark
	if mark != FilterColumns {
		return false
	}
	key := in.Key
	for _, column := range uc.filterColumns {
		if key == column {
			return true
		}
	}
	return false
}

func (uc *UpdateChain) AddColumn(column string) {
	uc.filterColumns = append(uc.filterColumns, column)
}
